package com.gking.centerSystem.common;

/**
 * 基于ThreadLocal封装工具类，用户保持和获取当前登录用户 id
 */
public class BaseContext {

    // 用于存储当前用户id
    private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void setCurrentId(String id) {
        threadLocal.set(id);
    }

    public static String getCurrentId() {
        return threadLocal.get();
    }


    // 存储请求响应体
    private static final ThreadLocal<String> threadLocalTwo = new ThreadLocal<>();

    public static void setResponseBody(String object) {
        threadLocalTwo.set(object);
    }

    public static String getResponseBody() {
        return threadLocalTwo.get();
    }


    // 存储登录验证码
    private static final ThreadLocal<String> threadLocalFour = new ThreadLocal<>();

    public static void setLoginVerifyCode(String code) {
        threadLocalFour.set(code);
    }

    public static String getLoginVerifyCode() {
        return threadLocalFour.get();
    }


    // 销毁存储的数据，以防内存泄漏等问题
    public static void destroy() {
        threadLocal.remove();
        threadLocalTwo.remove();
        threadLocalFour.remove();
    }

}
